/*
** Mortem's HGE Addon 1.4
** Copyright (C) 2006-2007, Osokin 'elmortem' Makar
** http://elmortem.mirgames.ru
**
** Widget engine.
*/

#ifndef _MHAENGINE_H_
#define _MHAENGINE_H_

#include <hge.h>

#define MHA_VERSION 0x140

class mhaEngine;
class mhaList;

class mhaWidget
#ifdef HGE_STATEMACHINE
: public HGEAPP
#endif
 {
public:
#ifndef HGE_STATEMACHINE
	mhaWidget(void) {
		hge = hgeCreate(HGE_VERSION);
		WidgetUpdateModal = false;
		WidgetRenderModal = false;
	}

	~mhaWidget(void) {
		hge->Release();
	}
	virtual void OnShow(void) {};
	virtual void OnHide(void) {};
	virtual void OnActive(void) {};
	
	virtual int Update(float delta) { return 0; };
	virtual void Render(void) {};
	virtual void FocusLost(void) {};
	virtual void FocusGain(void) {};
	virtual void GfxRestore(void) {};
	virtual bool Exit(void) { return true; };
	virtual HGE_CHAR *GetClassName(void) { return TXT("mhaWidget"); };
	
	bool WidgetUpdateModal;
	bool WidgetRenderModal;
#else
	mhaWidget(void) {
		hge = hgeCreate(HGE_VERSION);
	}
#endif
protected:
	static HGE *hge;
};

class mhaEngine {
public:
	mhaEngine(void);
	~mhaEngine(void);
	
	void Clear(void);
	void Show(mhaWidget *widget, bool renderModal = false);
	int ShowModal(mhaWidget *widget, bool renderModal = false);
	void Hide(mhaWidget *widget);
	HGE_CHAR *GetSavePath(void) { return SavePath; };
	float GetInGameTime(void) { return inGameTime; };

	bool Start(const HGE_CHAR *path, const HGE_CHAR *title);

	virtual bool PreInit(void) { return true; };
	virtual bool Init(void) { return true; };

	virtual bool Update(float delta);
	virtual bool Render(void);
	virtual bool FocusLost(void);
	virtual bool FocusGain(void);
	virtual bool GfxRestore(void);
	virtual bool Exit(void);
	
	static bool StaticUpdate(void);
	static bool StaticRender(void);
	static bool StaticFocusLost(void);
	static bool StaticFocusGain(void);
	static bool StaticGfxRestore(void);
	static bool StaticExit(void);

#ifndef HGE_STATEMACHINE
	void _render(void);
#endif

	// public data
	float Width, Height, HalfWidth, HalfHeight;
protected:
	static HGE *hge;
	static mhaEngine *Engine;

#ifndef HGE_STATEMACHINE
	mhaList *widgets;
	mhaWidget *RenderModal;
#endif

	HGE_CHAR SavePath[MAX_PATH];
	float inGameTime;
};

#endif
